Select/Copy Object Text based on Attribute

pragma runLim, 0;
Module m = current;
Object obj;
string answerMat[] = {"3-256","3-257"};
int i = 0;
string t = "true", f = "false";

print "Matrix Size: " sizeof answerMat "\n\n";

for obj in entire m do
{
        i++
        string AttrStr = obj."UniqueID";

        if(AttrStr == answerMat[0] || AttrStr == answerMat[1] )
        {
                print "Count- "i"\t" t"\n"
                
        }     else {
                                print "Count- "i "\t" f"\n"

                        }

}

 

Thanks' in advance for any help given!

Seeking only people with relevant advice -- No I don't need to hear "Try using the Search bar in the forum", because I have already used that and will continue to use it. 

I am looking for some advice or assistance in developing a DXL script that can loop through a module (I have this function down partially), and select/copy object text based on specific attribute text (part I need help with -- although I have been able to identify the specific text I am looking for, it is copying the object text I am trying to figure out. See below.)

We have developed a web API that generates a string array containing object identifiers. These object identifiers are used to find specific objects in our target module.  So far I have written a DXL script that is able to loop through a module and identify when the string we have been sent is identified. It is rudimentary, but I am a complete newby to coding and have been stumbling through the forum and DXL reference manual to piece it together. I figure you have to learn to walk before you run, so I am building it up piece by piece.

Does anyone have a suggestion on where to go next with this script? Suggestions on a more efficient method to pull out the specific object text? I have been using this forum and the DXL manual extensively, and maybe it's my lack of scripting experience but I haven't been able to find any posts that point me in the right direction. I will continue to search and if I do find the answer I will post the link here and mark it as answered.

 

**EDIT** We want to populate the built answerMat [ ]  with the object text we select. That will then be exported to a .txt file (for now).


dxlnewb - Tue May 29 19:28:05 EDT 2018

Re: Select/Copy Object Text based on Attribute
O.Wilkop - Wed May 30 07:09:45 EDT 2018

Instead of using a string array for your answers I suggest you look into using a Skiplist. While skiplists are a key-value datastructure, you can use them as a normal list, too.

So in the example above you would do something like this:

pragma runLim, 0;
Module m = current;
Object obj;
Skip answerMat = createString();
put(answerMat, "3-256", "3-256");
put(answerMat, "3-257", "3-257");
int i = 0;
string t = "true", f = "false";

for obj in entire m do
{
    i++
    string AttrStr = obj."UniqueID";

    if(find(answerMat, AttrStr))
    {
        print "Count- "i"\t" t"\n"
            
    }     else {
        print "Count- "i "\t" f"\n"

    }

}
delete(answerMat);

I suggest you read the chapter about SkipLists in the reference manual, there are some "tricks" and general things you should know when using them. Specifically the use of create() vs createString() when creating the Skiplist and how find() works with the optional parameter.